
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;


public class NIOTransportServer {
	public static void main(String[] args) throws IOException, InterruptedException {
		ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
		serverSocketChannel.socket().bind(new InetSocketAddress(90));
		SocketChannel socketChannel = serverSocketChannel.accept();
		FileChannel channel = (new FileOutputStream(args[0])).getChannel();
		System.out.println("Client was accepted");
		ByteBuffer byteBuffer = ByteBuffer.allocate(150000000);
        while (socketChannel.read(byteBuffer) != -1) {
               byteBuffer.flip();
               channel.write(byteBuffer);
               byteBuffer.clear();
        }
        socketChannel.close();
        channel.close();
    }
}
